Skip to content

Fix misleading tracer cache invalidation comment and simplify logic#97

Merged
YunchuWang merged 4 commits into
mainfrom
torosent/fix-otel
Feb 9, 2026
Merged

Fix misleading tracer cache invalidation comment and simplify logic#97
YunchuWang merged 4 commits into
mainfrom
torosent/fix-otel

Conversation

@torosent

@torosent torosent commented Feb 7, 2026

Copy link
Copy Markdown
Member

Summary

What changed?

  • Removed the unused _cachedOtel variable from trace-helper.ts
  • Simplified the tracer cache check from if (!_cachedTracer || _cachedOtel !== otel) to if (!_cachedTracer)
  • Replaced the misleading cache invalidation comment with an accurate explanation of why caching is safe

Why is this change needed?

The previous comment claimed "The cache is invalidated if the global tracer provider changes (e.g., in tests)" but the code only compared the OTEL API module reference (_cachedOtel !== otel). Since getOtelApi() always returns the same module object (due to Node's require() cache and internal _otelApiLoaded guard), this condition was never true after the first call — making _cachedOtel dead code and the comment misleading.

The tracer caching is actually safe because the OTEL JS SDK's trace.getTracer() returns a proxy tracer that dynamically delegates to the current global tracer provider. Provider swaps (e.g., via setGlobalTracerProvider() in tests) are handled transparently without needing to recreate the tracer. The new comment explains this correctly.

Issues / work items

  • N/A

Project checklist

  • Release notes are not required for the next release
  • Backport is not required
  • All required tests have been added/updated (unit tests, E2E tests)
    • No new tests needed; existing tracing tests (tracing.spec.ts, worker-tracing.spec.ts) continue to pass
  • Breaking change?
    • No

AI-assisted code disclosure (required)

Was an AI tool used? (select one)

  • No
  • Yes, AI helped write parts of this PR (e.g., GitHub Copilot)
  • Yes, an AI agent generated most of this PR

If AI was used:

  • Tool(s): GitHub Copilot
  • AI-assisted areas/files: packages/durabletask-js/src/tracing/trace-helper.ts — comment rewrite and dead code removal
  • What you changed after AI output: Reviewed the analysis of OTEL proxy tracer behavior and validated the change is correct

AI verification (required if AI was used):

  • I understand the code and can explain it
  • I verified referenced APIs/types exist and are correct
  • I reviewed edge cases/failure paths (timeouts, retries, cancellation, exceptions)
  • I reviewed concurrency/async behavior
  • I checked for unintended breaking or behavior changes

Testing

Automated tests

  • Result: Passed — 27 test suites, 464 tests (24 suites / 400 tests in durabletask-js, 3 suites / 64 tests in durabletask-js-azuremanaged)

Manual validation (only if runtime/behavior changed)

  • N/A — no runtime behavior change; this is a dead code removal and comment fix

Notes for reviewers

  • The OTEL JS SDK's trace.getTracer() returns a proxy tracer that delegates to the current global provider at call time. This means the cached tracer automatically picks up provider changes without invalidation, making the previous _cachedOtel check unnecessary.

Copilot AI review requested due to automatic review settings February 7, 2026 03:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Durable Task JS tracing layer, primarily around tracer caching and trace-context injection, and adjusts tracing conventions used by spans and tests.

Changes:

  • Introduces a cached tracer lookup via getTracingContext() and updates comments around why caching is safe.
  • Adds createPbTraceContextFromSpan() to build protobuf TraceContext directly from an OTEL Span, and switches injection sites to use it.
  • Updates timer span naming and adjusts expected tracing attributes/names in tests to match the updated conventions.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/durabletask-js/src/tracing/trace-helper.ts Adds cached tracer/context helper, uses it throughout span creation, and switches proto trace-context injection to createPbTraceContextFromSpan; also changes some durabletask.type values.
packages/durabletask-js/src/tracing/trace-context-utils.ts Adds createPbTraceContextFromSpan() helper for protobuf trace context creation directly from a span context.
packages/durabletask-js/src/tracing/constants.ts Updates timer span name format to orchestration:{orchName}:timer.
packages/durabletask-js/src/tracing/index.ts Re-exports createPbTraceContextFromSpan.
packages/durabletask-js/test/tracing.spec.ts Updates expected timer span naming and task-type attributes; adds coverage for createPbTraceContextFromSpan.
packages/durabletask-js/test/worker-tracing.spec.ts Updates sub-orchestration scheduling span expectations to match updated durabletask.type conventions and span kind filtering.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/durabletask-js/src/tracing/trace-context-utils.ts Outdated
Comment thread packages/durabletask-js/test/tracing.spec.ts
Comment thread packages/durabletask-js/src/tracing/trace-helper.ts

Copilot AI commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

@torosent I've opened a new pull request, #98, to work on those changes. Once the pull request is ready, I'll request review from you.

Comment thread .gitignore Outdated
@YunchuWang

Copy link
Copy Markdown
Member
image

@YunchuWang

Copy link
Copy Markdown
Member
image

Copilot AI commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

@torosent I've opened a new pull request, #99, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits February 9, 2026 12:08
…atePbTraceContextFromSpan signature

- Revert setSpanError and setSpanOk to call getOtelApi() instead of
  getTracingContext(), since they only need SpanStatusCode (no tracer)
- Widen createPbTraceContextFromSpan parameter type to Span | undefined | null
  for consistency with extractTraceparentFromSpan
@YunchuWang YunchuWang merged commit fb988d4 into main Feb 9, 2026
10 checks passed
@YunchuWang YunchuWang deleted the torosent/fix-otel branch February 9, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants